<!--
 * @Descripttion: 正则学习-使用变量
 * @Author: YuZhenJing
 * @Date: 2020-06-20 11:16:14
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-06-21 14:47:47
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let ay = "anyuncangge.com";
      let reg = "[a-z]";
      // 通过 eval 方式使用变量
      console.log(eval(`/${reg}/`).test(ay));
      // 通过 RegExp 对象使用变量
      console.log(new RegExp(reg).test(ay));
    </script>
  </body>
</html>
